package com.jjty.dataGenerator.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: huangyulong
 * @createTime: 2023-04-04 15:45
 * @Description: 统一响应对象
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ApiResult {

    /**
     * 成功状态码
     */
    public static final int SUCCESS_CODE = 200;

    /**
     * 失败状态码
     */
    public static final int FAILURE_CODE = 500;


    private Integer code;

    private String msg;

    private Object response;


    /**
     * 操作成功
     * @param msg 提示消息
     * @return
     */
    public static ApiResult doSuccess(String msg, Object response){
        return new ApiResult(200,msg,response);
    }

    public static ApiResult doSuccess(String msg){
        return new ApiResult(200,msg,null);
    }

    public static ApiResult doSuccess(){
        return new ApiResult(200,"操作成功",null);
    }


    /**
     * 操作失败
     * @param msg 响应对象
     * @return
     */
    public static ApiResult doFailure(String msg){
        return new ApiResult(500,msg,null);
    }

    public static ApiResult doFailure(){
        return new ApiResult(500,"操作失败",null);
    }


    /**
     * 查询成功
     * @param response
     * @return
     */
    public static ApiResult querySuccess(Object response){
        return new ApiResult(200,"查询成功",response);
    }

    /**
     * 查询失败
     * @return
     */
    public static ApiResult queryFailure(){
        return new ApiResult(200,"查询失败",null);
    }





}
